package com.wangy.sct.common.web.configuration;

import com.wangy.sct.common.core.*;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * ClassName: GlobalExceptionHandler <br/>
 * Description:  <br/>
 *
 * @author wangyue
 * @version V1.0.0
 * @date 2018/11/8 4:43 PM
 */
@ControllerAdvice
public class GlobalControllerAdvice {

	@ResponseBody
	@ExceptionHandler(Exception.class)
	public InvokeResult handleException(Exception e) {
		e.printStackTrace();
		InvokeResult invokeResult = new InvokeResult();
		if (e instanceof SctException || e instanceof SctRuntimeException) {
			return invokeResult.setStatus(((SctExceptionDescription) e));
		} else {
			return invokeResult.setStatus(SctEnum.UNKNOWEN_EXCEPTION);
		}
	}

}
